package com.jzo2o.orders.dispatch.demo;

import com.jzo2o.common.utils.CollUtils;
import com.jzo2o.orders.dispatch.model.dto.ServeProviderDTO;

import java.util.List;

/**
 * @version V1.0
 * @date 2025-04-15 16:45
 */
public abstract class AbstractProcessRule implements IProcessRule {

	private IProcessRule next;

	public AbstractProcessRule(IProcessRule next) {
		this.next = next;
	}

	/**
	 * 派单规则过滤方法
	 * 模板方法
	 *
	 * @param: serveProviderDTOS
	 * @return:
	 */
	public abstract List<ServeProviderDTO> doFilter(List<ServeProviderDTO> serveProviderDTOS);

	@Override
	public List<ServeProviderDTO> filter(List<ServeProviderDTO> serveProviderDTOS) {
		List<ServeProviderDTO> list = this.doFilter(serveProviderDTOS);
		if (CollUtils.size(list) > 1 && next != null) {
			return next.filter(list);
		} else {
			return list;
		}
	}

	@Override
	public IProcessRule next() {
		return next;
	}

}
